using System;

namespace Beeflys
{
    public delegate void ResponseDelegate<TResponse>(ActorResult<TResponse> result);

    abstract class ACallbackSponsor<TResponse> : AResponsiveSponsor
    {
        protected ACallbackSponsor(ResponseDelegate<TResponse> completed, TimeSpan timeout)
            : base(timeout)
        {
            this.completed = completed;
        }

        private ResponseDelegate<TResponse> completed;

        protected override void OnResponseReturn(object o, ActorOpencode opencode)
        {
            completed(new ActorResult<TResponse>(opencode, (TResponse)o));
        }
    }
}
